package com.jzlin.funhub.admin.model.entity;

import cn.hutool.core.lang.tree.TreeNode;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.annotation.TableName;
import com.jzlin.funhub.framework.core.db.BaseEntity;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

/**
 * <p>
 * 文章分类表
 * </p>
 *
 * @author jzlin
 * @since 2025-07-17
 */
@Getter
@Setter
@TableName("article_category")
public class ArticleCategory extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 分类名称
     */
    private String name;


    /**
     * 优先级
     */
    private Integer weight;

    /**
     * 图标
     */
    private String icon;

    /**
     * 父级分类id
     */
    private Long parentId;

    public TreeNode<Long> toTreeNode() {
        TreeNode<Long> treeNode = new TreeNode<>(id, parentId, name, weight);
        if (StrUtil.isNotBlank(icon)) {
            treeNode.setExtra(Map.of("icon", icon));
        }

        return treeNode;
    }
}
